package com.atguyigu.codesday01.dom02;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class NewTicket {
     private int number = 50;
    Lock lock = new ReentrantLock();

   public  void  sale(){
         //上锁
       lock.lock();

       try {
           if (number>0){
               System.out.println(Thread.currentThread().getName()+"\t"+"卖出第: "+(number--)+"\t 还剩下: "+number);

           }
       } finally {
           //释放锁
         lock.unlock();
       }
   }
}
